<?php
/*
	[Bidcms.com!] (C)2009-2011 Bidcms.com.
	This is NOT a freeware, use is subject to license terms
	$author limengqi
	$Id: setpin.php 2010-08-24 10:42 $
*/
include '../inc/common.simple.php';
include '../inc/pin.inc.php';
$uid=$session->get('uid');

$pin_id=intval($_REQUEST['id']);
$text=isset($_POST['text'])?trim(strip_tags($_POST['text'])):'';
if(!empty($text) && $pin_id>0  && $uid>0)
{
	$sql="insert into ".tname("comments")." (pin_id,user_id,raw_text,created_at) values('".$pin_id."','".$uid."','".$text."','".time()."')";
	$db->query($sql);
	$cid=$db->insert_id();
	if($cid>0)
	{
		$db->query("update ".tname('pin')." set comment_count=comment_count++1 where pin_id=".$pin_id);
		$comment=array('pin_id'=>$pin_id,'user_id'=>$uid,'raw_text'=>$text,'text_meta'=>array(),'created_at'=>time(),'comment_id'=>$cid);
		$comment['pin']=getpin($pin_id);
		$comment['user']=getuser($uid,1);
        mysql_query("insert into ".tname('feeds')."(user_id,created_at,feedtype,feedpid) values('".$uid."','".time()."','comment','".$pin_id."')");
		echo bidcms_encode(array('comment'=>$comment));
		exit;
	}
	else
	{
		echo '{"err":1,"msg":"评论失败"}';
		exit;
	}
}
else
{
	echo '{"err":1,"msg":"评论失败"}';
	exit;
}
?>
